package com.ycw.service.guoguo.impl;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ycw.bean.Users;
import com.ycw.dao.UsersMapper;
import com.ycw.util.CodeUtil;
import com.ycw.util.MailUtil;
import com.ycw.util.Msg;
@Service
public class UserRegistrationServiceImpl implements com.ycw.service.guoguo.UserRegistrationService {

	@Autowired
	private UsersMapper usersMapper;
	
	@Override
	public Msg getMailOnlyOne(Users users, HttpSession httpSession) {
		Users user = usersMapper.selectOne(users);
		if(user!=null){
			return Msg.fail();
		}else{
			String usCode = CodeUtil.generateUniqueCode();
			httpSession.setAttribute("usCode", usCode);
			MailUtil.UserRegistration(users.getUsEmail(), usCode);
			return Msg.success();
		}
		
	}

	@Override
	public Msg getUsCode(Users users, HttpSession httpSession) {
		String usCode = (String) httpSession.getAttribute("usCode");
	
		if(usCode.equals(users.getUsCode())){
			return Msg.success();
		}
		return Msg.fail();
	}

	@Override
	public Msg getUsIdCardOrPhoneOnlyOne(Users users) {
		Users user = usersMapper.selectOne(users);
		if(user!=null){
			return Msg.fail();
		}
		return Msg.success();
	}



	@Override
	public Msg addUsrs(Users users) {
		if(usersMapper.insertSelective(users)>0){
			return Msg.success();
		}
		return Msg.fail();
	}

}
